package service.impl;

import dao.OrderDAO;
import dao.impl.OrderDAOImpl;
import model.Order;
import service.OrderService;

import java.util.List;

public class OrderServiceImpl extends BaseServiceImpl implements OrderService {
    private OrderDAO orderDAO;

    @Override
    public Order handleSetOrder(Order order) throws Exception {
        orderDAO = new OrderDAOImpl();
        List<Order> orderList = orderDAO.getOrderList();
        if(orderList != null){
            for (Order o: orderList){
                if(o.getUserId().equals(order.getUserId())){
                    context.put(ORDER_USER,o);
                    return o;
                }
            }
        }
        return null;
    }

    @Override
    public Order handleGetOrder() throws Exception {
        Object obj = context.get(ORDER_USER);
        if(obj != null){
            return (Order) obj;
        }
        return null;
    }
}
